<div class="layui-container fly-marginTop">
    <div class="fly-panel" pad20 style="padding-top: 5px;">
        #shiroGuest()
        <div class="fly-none">没有登录</div>
        #end

        #shiroAuthenticated()
        <div class="layui-form layui-form-pane">
            <div class="layui-tab layui-tab-brief" lay-filter="user">
                <ul class="layui-tab-title">
                    <li class="layui-this">发布文章</li>
                </ul>
                <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                    <div class="layui-tab-item layui-show">
                        <form class="layui-form layui-form-pane" action="">

                            <div class="layui-row layui-col-space15 layui-form-item">
                                <!--<div class="layui-col-md3">-->
                                    <!--<label class="layui-form-label">所在专栏</label>-->
                                    <!--<div class="layui-input-block">-->

                                        <!--<select disabled="" name="class" lay-filter="column">-->
                                            <!--<option></option>-->
                                            <!--<option value="0">提问</option>-->
                                            <!--<option value="99">分享</option>-->
                                            <!--<option value="100">讨论</option>-->
                                            <!--<option value="101">建议</option>-->
                                            <!--<option value="168">公告</option>-->
                                            <!--<option value="169">动态</option>-->
                                        <!--</select>-->

                                    <!--</div>-->
                                <!--</div>-->
                                <div class="layui-col-md12">
                                    <label for="L_title" class="layui-form-label">标题</label>
                                    <div class="layui-input-block">
                                        <input type="text" id="L_title" name="title" required lay-verify="required"
                                               autocomplete="off" class="layui-input" value="">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <div class="layui-input-block">
                                    <link rel="stylesheet" href="/static/libs/editormd/css/editormd.min.css"/>
                                    <div id="editormd">
                                        <textarea name="content" style="display:none;"></textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <button class="layui-btn" lay-submit="" lay-filter="sendForm">立即发布</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        #end

    </div>
</div>


<script src="/static/libs/editormd/editormd.min.js"></script>
<script type="text/javascript">
    $(function () {
        var editor = editormd("editormd", {
            path: "/static/libs/editormd/lib/", // Autoload modules mode, codemirror, marked... dependents libs path
            height: 640,
            toolbarAutoFixed: false,
            saveHTMLToTextarea: true,
            syncScrolling: "single",
            onfullscreen: function () {
                var oDiv = document.getElementById('editormd');
                oDiv.style.zIndex = 99999;   //这时候你在审查div这个元素的时候，发现z-index的值为10；
            },
            onfullscreenExit: function () {
                var oDiv = document.getElementById('editormd');
                oDiv.style.zIndex = 0;   //这时候你在审查div这个元素的时候，发现z-index的值为10；
            }
        });

        /*
         // or
         var editor = editormd({
         id   : "editormd",
         path : "../lib/"
         });
         */
    });
</script>


<script>
    layui.use(['element', 'form'], function () {
        var element = layui.element;
        var form = layui.form;

        //监听提交
        form.on('submit(sendForm)', function (data) {

            console.log(JSON.stringify(data.field));
            layui.$.ajax({
                type: "post",
                contentType: "application/json;charset=utf-8", // 因为上面是JSON数据
                url: '/article/add',
                data: JSON.stringify(data.field),
                success: function (data) {

                    if (200 === data.code) {
                         layer.msg('发布成功');
                         location.href='/article';
                    }

                    console.log(data);
                },
                error: function (data, textStatus, errorThrown) {
                    layer.msg("发布失败");
                    console.log(data);
                }
            });

            return false;
        });


    });
</script>